package com.cmcc.passenger.ui.tripoption

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.cmcc.passenger.data.AppRequest
import com.cmcc.passenger.data.PassDataRepository
import com.cmcc.passenger.data.entity.response.*
import com.cmcc.shared.SdkManager
import com.cmcc.shared.utils.L
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

/**
 * Author: jiangxin
 * Date: 2019/11/14
 * Description:
 */
class TripOptionsViewModel : ViewModel() {
    private val travelItem = MutableLiveData<TravelItem>()

    fun getTunnels(): MutableLiveData<List<Tunnel>> {
        return PassDataRepository.getInstance().getTunnels()
    }

    fun getTips(): MutableLiveData<List<Gratuity>> {
        return PassDataRepository.getInstance().getTips()
    }

    fun getCarTypes(): MutableLiveData<List<CarCategory>> {
        return PassDataRepository.getInstance().getCarCategories()
    }

    fun getStations(): MutableLiveData<List<Station>> {
        return PassDataRepository.getInstance().getStations()
    }

    fun getTravelItem(): MutableLiveData<TravelItem> {
        viewModelScope.launch(Dispatchers.Main) {
            try {
                val response = AppRequest.getInstance().getTravelItemList()
                if (response.isSuccessful) {
                    response.body()?.data?.let {
                        travelItem.value = it
                        PassDataRepository.getInstance().getTunnels().value = it.tunnels
                        PassDataRepository.getInstance().getCarCategories().value = it.vehicleTypes
                        PassDataRepository.getInstance().getTips().value = it.gratuityItems
                        PassDataRepository.getInstance().getRemarks().value = it.remakes
                    }
                } else {

                }
            } catch (e: Exception) {
                L.d("e :" + e.message + "," + e.cause)
            }
        }
        return travelItem
    }

    fun getRemarks(): MutableLiveData<List<Remark>> {
        return PassDataRepository.getInstance().getRemarks()
    }
}